<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../../js/theme/default/layer.css" media="all" />
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<input type="hidden" id="id" name="id">
			<input type='hidden' name='contactId' id='contactId' >
<!--            <div class='form-group'>-->
<!--				<label class='col-md-2 control-label'>contactId</label>-->
<!--				<div class='col-md-10'>-->
<!--					<input class='form-control' placeholder='contactId' type='text' name='contactId' id='contactId' data-bv-notempty='true' data-bv-notempty-message='contactId 不能为空'>-->
<!--				</div>-->
<!--			</div>-->
<!--			<div class='form-group'>-->
<!--				<label class='col-md-2 control-label'>createDate</label>-->
<!--				<div class='col-md-10'>-->
<!--					<input class='form-control' placeholder='createDate' type='text' name='createDate' id='createDate' data-bv-notempty='true' data-bv-notempty-message='createDate 不能为空'>-->
<!--				</div>-->
<!--			</div>-->
<!--			<div class='form-group'>-->
<!--				<label class='col-md-2 control-label'>creater</label>-->
<!--				<div class='col-md-10'>-->
<!--					<input class='form-control' placeholder='creater' type='text' name='creater' id='creater' data-bv-notempty='true' data-bv-notempty-message='creater 不能为空'>-->
<!--				</div>-->
<!--			</div>-->
<!--			<div class='form-group'>-->
<!--				<label class='col-md-2 control-label'>modifyDate</label>-->
<!--				<div class='col-md-10'>-->
<!--					<input class='form-control' placeholder='modifyDate' type='text' name='modifyDate' id='modifyDate' data-bv-notempty='true' data-bv-notempty-message='modifyDate 不能为空'>-->
<!--				</div>-->
<!--			</div>-->
<!--			<div class='form-group'>-->
<!--				<label class='col-md-2 control-label'>modifyer</label>-->
<!--				<div class='col-md-10'>-->
<!--					<input class='form-control' placeholder='modifyer' type='text' name='modifyer' id='modifyer' data-bv-notempty='true' data-bv-notempty-message='modifyer 不能为空'>-->
<!--				</div>-->
<!--			</div>-->
			<div class='form-group'>
				<label class='col-md-2 control-label'>影响干系人关系</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='stakeholderRelationship' type='text' name='stakeholderRelationship' id='stakeholderRelationship' data-bv-notempty='true' data-bv-notempty-message='stakeholderRelationship 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>姓名</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='stakeholderName' type='text' name='stakeholderName' id='stakeholderName' data-bv-notempty='true' data-bv-notempty-message='stakeholderName 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>事件</label>
				<div class='col-md-10'>
					<table id="eventRecord" border="1" width="100%" style="text-align: center">
						<thead style="text-align: center">
						<th style="text-align: center" width="5%"><button type="button" class="layui-btn" onclick="addRow()"><i class="layui-icon"></i></button></th>
						<th style="text-align: center">事件</th>
						<th style="text-align: center">时间</th>
						<th style="text-align: center"></th>
						</thead>
						<tbody>
						<!--						<tr id="row0" style="text-align: center">-->
						<!--							<td>1</td>-->
						<!--							<td><input id='event0' name='event'></td>-->
						<!--							<td><input id='eventDate0' name='eventDate' readonly="readonly"></td>-->
						<!--							<td><button class='layui-btn layui-btn-xs' title='删除' onclick=''><i class='layui-icon'>&#xe640;</i></button></td>-->
						<!--						</tr>-->
						</tbody>
					</table>
				</div>
			</div>

			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <button class="btn btn-primary" onclick="goBack()">返回</button>
						<button class="btn btn-primary" type="submit" onclick="update()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>
		</fieldset>
	</form>
</div>
<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
	<script type="text/javascript">
		var rowNum = 1;
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		});
		initData();
		function initData(){
			var id = getUrlParam("id");
			if(id != ""){
				$.ajax({
					type : 'get',
					url : '/customContactStakeholder/getInfo/'+id,
					async : false,
					success : function(data) {
                        $('#contactId').val(data.contactId);
						$('#createDate').val(data.createDate);
						$('#creater').val(data.creater);
						$('#id').val(data.id);
						$('#modifyDate').val(data.modifyDate);
						$('#modifyer').val(data.modifyer);
						$('#stakeholderName').val(data.stakeholderName);
						$('#stakeholderRelationship').val(data.stakeholderRelationship);
						//这里的rowId就是row加上标志位的组合。是每新增一行的tr的id。
						var rowId = "row" + rowNum;
						var tr = '';
						for(var i =0; i < data.event.length; i++){
							// var contactData = data.eventList[i];
							tr += "<tr id='"+rowId+"' style='text-align: center'><td>"+rowNum+"</td>";

							tr +=   "<td><input id='event"+rowNum+"' name='event' value='"+data.event[i]+"'></td>" +
									" <td><input id='eventDate"+rowNum+"' name='eventDate' value='"+data.eventDate[i]+"'></td> " +
									"<td><button class='layui-btn layui-btn-xs' title='删除' onclick=''><i class='layui-icon'>&#xe640;</i></button></td></tr>";
							rowNum++;
						}
						//这里的行数减2，是因为要减去底部的一行和顶部的一行，剩下的为开始要插入行的索引
						$("#eventRecord tbody").append(tr); //将新拼接的一行插入到当前行的下面
					}
				});
			}
		}
		function update() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    var formdata = $("#form").serializeObject();
			$.ajax({
				type : 'post',
				url : '/customContactStakeholder/editInfo',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                        location.href = "customContactStakeholderList.html";
                    });
				}
			});
		}
		function goBack(){
			// var type = $("#type").val();
			var contactId = $("#contactId").val();
			location.href='customContactStakeholderList.html?contactId='+contactId ;//+'&type='+type
		}

		function addRow() {
			//获取表格有多少行
			var rowLength = $("#eventRecord tr").length;
			//这里的rowId就是row加上标志位的组合。是每新增一行的tr的id。
			var rowId = "row" + rowNum;

			var th = "<tr id='"+rowId+"' style='text-align: center'><td>"+rowNum+"</td>";

			th +=   "<td><input id='event"+rowNum+"' name='event'></td>" +
					" <td><input id='eventDate"+rowNum+"' name='eventDate' readonly='readonly'></td> " +
					"<td><button class='layui-btn layui-btn-xs' title='删除' onclick=''><i class='layui-icon'>&#xe640;</i></button></td></tr>";


			//这里的行数减2，是因为要减去底部的一行和顶部的一行，剩下的为开始要插入行的索引
			$("#eventRecord tr:eq(" + (rowLength - 1) + ")").after(th); //将新拼接的一行插入到当前行的下面

			layui.use(['layer','laydate'], function(){
				var layer = layui.layer;
				var laydate = layui.laydate;
				laydate.render({
					elem: '#eventDate'+rowNum,
					trigger: 'click'
				});
			});
			rowNum += 1;
		}
	</script>
</body>
</html>
